package com.ruoyi.web.controller.business;


import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.AdsDetails;
import com.ruoyi.system.domain.LedAds;
import com.ruoyi.system.service.IAdsDetailsService;
import com.ruoyi.system.service.ILedAdsService;
import com.ruoyi.web.controller.demo.domain.UserOperateModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * LEDController
 * 
 * @author ruoyi
 * @date 2024-03-14
 */
@Controller
@RequestMapping("/led/ads")
public class LedAdsController extends BaseController
{
    private String prefix = "business/led/";

    @Autowired
    private IAdsDetailsService adsDetailsService;

    @Autowired
    private ILedAdsService ledAdsService;

    @GetMapping()
    public String ads()
    {
        return prefix + "/ads";
    }

    /**
     * 查询LED列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LedAds ledAds)
    {
        startPage();
        List<LedAds> list = ledAdsService.selectLedAdsList(ledAds);
        return getDataTable(list);
    }

    public static void main(String[] args) throws SQLException {
        Connection conn = DriverManager.getConnection("jdbc:mysql:///ry", "root", "root");

        // ResultSet rs = conn.prepareStatement("select * from led_ads").executeQuery();
        //System.out.println(rs.next());
        //System.out.println(rs.getString(2));

//        for (int i = 6; i <= 13843; i++) {
//            String sql = "INSERT INTO `ry`.`ads_details`( `ads_id`, `ads_name`, `ads_count`, `submit_date`, `send_persion_phone`, `status`) VALUES ("+i+", '汉廷', '4', '2024-02-18 00:00:00', '15660000369', 1)";
//            boolean execute = conn.prepareStatement(sql).execute();
//            System.out.println(execute);
//        }
//        for (int i = 5; i <= 13843; i++) {
//            String sql = "INSERT INTO `ry`.`ads_details`( `ads_id`, `ads_name`, `ads_count`, `submit_date`, `send_persion_phone`, `status`) VALUES ("+i+", '河南优帮科技集团“二', '5', '2024-03-15 17:28:18', '15660000369 ', 1)";
//            boolean execute = conn.prepareStatement(sql).execute();
//            System.out.println(execute);
//        }
//        for (int i = 5; i <= 13843; i++) {
//            String sql = "INSERT INTO `ry`.`ads_details`( `ads_id`, `ads_name`, `ads_count`, `submit_date`, `send_persion_phone`, `status`) VALUES ("+i+", '领航网约车服务中心', '7', '2024-03-15 17:28:38', '15660000369', 1)";
//            boolean execute = conn.prepareStatement(sql).execute();
//            System.out.println(execute);
//        }
//        for (int i = 5; i <= 13843; i++) {
//            String sql = "INSERT INTO `ry`.`ads_details`( `ads_id`, `ads_name`, `ads_count`, `submit_date`, `send_persion_phone`, `status`) VALUES ("+i+",  '河南优帮科技集团三', '8', '2024-03-15 17:29:02', '15660000369', 1)";
//            boolean execute = conn.prepareStatement(sql).execute();
//            System.out.println(execute);
//        }

    }
    /**
     * 导出LED列表
     */
    @Log(title = "LED", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LedAds ledAds)
    {
        List<LedAds> list = ledAdsService.selectLedAdsList(ledAds);
        ExcelUtil<LedAds> util = new ExcelUtil<LedAds>(LedAds.class);
        return util.exportExcel(list, "LED数据");
    }

    /**
     * 新增LED
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存LED
     */
    @Log(title = "LED", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LedAds ledAds)
    {
        return toAjax(ledAdsService.insertLedAds(ledAds));
    }

    /**
     * 修改LED
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LedAds ledAds = ledAdsService.selectLedAdsById(id);
        mmap.put("ledAds", ledAds);
        return prefix + "edit";
    }

    /**
     * 修改保存LED
     */
    @Log(title = "LED", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LedAds ledAds)
    {
        return toAjax(ledAdsService.updateLedAds(ledAds));
    }

    /**
     * 删除LED
     */
    @Log(title = "LED", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ledAdsService.deleteLedAdsByIds(ids));
    }

    @Log(title = "LED", businessType = BusinessType.OTHER)
    @GetMapping( "/parent")
    public String parent(String id, Model model)
    {
        System.out.println(id);
        model.addAttribute("id",id);
        return prefix + "parent";
    }

    @Log(title = "LED", businessType = BusinessType.OTHER)
    @PostMapping( "/adsList")
    @ResponseBody
    public TableDataInfo adsList(String adsId)
    {
        TableDataInfo rspData = new TableDataInfo();
        AdsDetails details = new AdsDetails();
        details.setAdsId(Long.parseLong(adsId));
        List<AdsDetails> list = adsDetailsService.selectAdsDetailsList(details);
        rspData.setRows(list);
        rspData.setTotal(list.size());
        return rspData;
    }

}
